package cn.funeralobjects.ams.web.mapper;

import cn.funeralobjects.ams.entity.EAccess;
import cn.funeralobjects.ams.web.model.VAccess;
import cn.funeralobjects.common.web.controller.converter.VoMapper;
import org.mapstruct.Mapper;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author FuneralObjects
 * Create date: 2020/5/26 10:19 AM
 */
@Mapper(componentModel = "spring")
public interface AccessMapper extends VoMapper<EAccess, VAccess> {

    /**
     * entity -> id
     *
     * @param entity entity
     * @return id
     */
    default Integer getId(EAccess entity) {
        return entity == null ? null : entity.getId();
    }

    /**
     * id -> entity
     *
     * @param id id
     * @return entity
     */
    default EAccess setId(Integer id) {
        EAccess entity = new EAccess();
        entity.setId(id);
        return entity;
    }

    /**
     * entity -> id
     *
     * @param entities entity
     * @return id
     */
    default List<Integer> getId(List<EAccess> entities) {
        if (entities == null) {
            return new ArrayList<>(0);
        }
        return entities.stream().map(this::getId).collect(Collectors.toList());
    }

    /**
     * id -> entity
     *
     * @param ids id
     * @return entity
     */
    default List<EAccess> setId(List<Integer> ids) {
        if (ids == null) {
            return new ArrayList<>(0);
        }
        return ids.stream().map(this::setId).collect(Collectors.toList());
    }
}
